package org.springblade.modules.customer.wrapper;


import org.springblade.common.entity.DictVO;
import org.springblade.core.mp.support.BaseEntityWrapper;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.customer.entity.Customer;
import org.springblade.modules.customer.vo.CustomerVO;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 客户表包装类,返回视图层所需的字段
 *
 * @author armyant
 * @since 2024-04-21
 */
public class CustomerWrapper extends BaseEntityWrapper<Customer, CustomerVO> {

	public static CustomerWrapper build() {
		return new CustomerWrapper();
	}

	@Override
	public CustomerVO entityVO(Customer customer) {
		CustomerVO vo = BeanUtil.copy(customer, CustomerVO.class);
		if (Func.isNoneBlank(customer.getLabel())) {
			List<DictVO> dictVOS = Arrays
				.stream(Func.splitTrim(customer.getLabel(), "|"))
				.map(item -> DictVO.builder().dictKey(item).dictValue(item).build())
				.collect(Collectors.toList());
			assert vo != null;
			vo.setLabel(dictVOS);
		}
		return vo;
	}
}
